<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../layuimini/lib/layui-v2.6.3/css/layui.css" media="all">
    <script src="../layuimini/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
    <link rel="stylesheet" href="../layuimini/css/public.css" media="all">
    <script src="../layuimini/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">


    <!-- 地区选择 -->
    <div class="layui-form-item" id="area-picker">
        <div class="layui-form-label">户籍所在地</div>
        <div class="layui-input-inline" style="width: 200px;">
            <select name="tProvince" class="province-selector" data-value="江西省" lay-filter="province-1">
                <option value="">请选择省</option>
            </select>
        </div>
        <div class="layui-input-inline" style="width: 200px;">
            <select name="tCity" class="city-selector" data-value="上饶市" lay-filter="city-1">
                <option value="">请选择市</option>
            </select>
        </div>
        <div class="layui-input-inline" style="width: 200px;">
            <select name="tCounty" class="county-selector" data-value="铅山县" lay-filter="county-1">
                <option value="">请选择 县/区</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">详细地址</label>
        <div class="layui-input-block">
            <input type="text" name="tDetailed" value="" class="layui-input">
        </div>
    </div>


    <div class="layui-form-item">
        <div class="layui-input-block">
            <button id="log-btn" class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
<script>
    layui.use(['layer' , 'form' , 'layarea' , 'laydate'], function () {
        var form = layui.form,
            layer = layui.layer,
            laydate = layui.laydate,
            layarea = layui.layarea,
            $ = layui.$;

        //地区选择控件
        layarea.render({
            elem: '#area-picker',
        });

        //监听提交
        form.on('submit(saveBtn)', function (data) {

                //这里需要转为JSON格式
                var da = JSON.stringify(data.field);

                $("#log-btn").attr("disabled","disabled").addClass("layui-btn-disabled");

                $.ajax({
                    //注意：这里需要添加/
                    url:"/area/addArea",
                    method: "post",
                    data: da,
                    contentType: "application/json;charset=UTF-8",   // 注意：这里需要设置请求头，因为springmvc中默认接收的请求头为这个
                    dataType: "json",
                    success: function (res){
                        if(res.code == 0){
                            layer.msg("添加成功",{ icon: 6,time: 2000,anim: 5},function (){
                                //刷新表格数据
                                parent.refreshTable();
                                //关闭窗口
                                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                parent.layer.close(index); //再执行关闭
                            });
                        }else{
                            $("#log-btn").removeAttr("disabled","disabled").removeClass("layui-btn-disabled");
                            layer.msg(res.msg,{ icon: 2,time: 1000,anim: 6});
                        }
                    }
                })
                // // 关闭弹出层
                // layer.close(index);

                return false;
        });

    });
</script>
</body>
</html>